#if defined(__MMI_DSM_NEW__) && defined( __HC_CALL_NEW__)
/*-------------------------------------------------------------------------------*

--------------------------------------------------------------------------------*/
#include "dsm_datatype.h" 

#include "GlobalMenuItems.h"
#include "GlobalDefs.h"
#include "GlobalConstants.h" //KEY_EVENT_UP
#include "HistoryGprot.h"  //extern void GoBackHistory()
#include "HcCallDef.h"
#include "HcCallIn_UI.h"
#include "MainMenuDef.h"
#include "wgui_inline_edit.h"
#include "HcFileAdapter.h"
#include "CommonScreens.h"
#include "app_datetime.h"
#include "timerEvents.h"

#include "UCMGProt.h"
#include "PhoneBookTypes.h"
#include "MTPNP_AD_resdef.h"
#include "PhoneBookProt.h"
#include "PhoneBookResDef.h"
#include "Mtpnp_ad_common_def.h"

#include "ems.h"
#include "SmsGuiInterfaceType.h"

#ifdef __MMI_DUAL_SIM_MASTER__
#include "MTPNP_AD_master_if.h"
#endif

#include "SMSApi.h"
#include "MessagesresourceData.h"
#include "SettingProfile.h"
#include "PixtelDatatypes.h"
#include "SimDetectionDef.h"
#include "USBDeviceGprot.h"
#include "FileManagerGProt.h"
#include "UCMResDef.h"


#include "mrp_unet.h"
#include "mrp_sms.h"
#include "mrp_sysinfo.h"

#include "hccall_net.h"
#include "Section_Data.h"

#include "ldzs.h"
#include "mmi_rp_app_hccall_def.h"
#include "mrp_features.h"
#include "IdleAppResDef.h"
#define HELP_LIST_COUNT (3)


//////////////////////////////////////////////////////////////////////
//extern functions:
//////////////////////////////////////////////////////////////////////
extern void HighlightDsmGame(void);

extern int LocationData_Init_ex(void);
extern int GetLocation_ex( char *area, int size, char *tel );
extern void hccall_set_firmdatabase(const unsigned char* pFirmDatabase, uint32 firmDatabase);
extern int HC_get_driver_char(int type);

extern void mmi_mtpnp_entry_menu(U16 scr_id, FuncPtr exit_func, FuncPtr entry_func, U16 menu_id, U16 str_id, U16 img_id);
extern void ShowCategory401Screen(U16 percentage);
extern void mmi_phb_entry_main_menu(void);
//USB
#ifdef __USB_IN_NORMAL_MODE__
extern pBOOL mmi_usb_is_in_mass_storage_mode(void);
#ifndef WIN32
extern void mmi_usb_app_unavailable_popup(U16 stringId);
#endif
#endif

extern void hccall_start_host_timer(U32 delay, FuncPtr funcPtr);
extern void hccall_stop_host_timer(void);


//////////////////////////////////////////////////////////////////////
//global variables:
//////////////////////////////////////////////////////////////////////

extern HCCALL_NETSTATE g_hccall_netstate;
extern const U16 gIndexIconsImageList[];


//section
char   g_HCNumber[HCNUMBER_LEN];
char   g_HCStrLocation[HCSTRLOCATION_LEN];
char   g_HCStrGsdLocation[HCSTRLOCATION_LEN];
char   g_HcStr_Number[HCNUMBER_LEN];

static U16 Hc_func_setting_item = 0;



/********************************************************************
Function:		hccall_load_userconfig
Description: 	load the user's config setting
Input:		void
Output:		g_HcUserConfig_p
Return:		1: success; 0:failed
Notice:		
*********************************************************************/
int hccall_load_userconfig(HCCALL_CONFIG *g_HcUserConfig_p)
{
	int32 fhandle = 0;
	uint32 readCount;
	int32 result = 0;
	
	result = HcFile_Open(&fhandle, (int8*)HCUSER_CONFIG_F ,PO_RDONLY, 0);

	if( !result )
	{
		if( fhandle > 0 )
		{
			HcFile_Close(fhandle, 0);
		}
		return result;
	}
	HcFile_Read(fhandle, g_HcUserConfig_p, sizeof(HCCALL_CONFIG), &readCount, 0);
	if(readCount == sizeof(HCCALL_CONFIG))
	{
		result  = 1;
	}
	else
	{
		result  = 0;
	}
	
	HcFile_Close(fhandle, 0);

	return result;
}


/********************************************************************
Function:		hccall_save_userconfig
Description: 	save the user's config setting
Input:		user's config setting
Output:		void
Return:		1: success; 0:failed
Notice:		
*********************************************************************/
int hccall_save_userconfig(HCCALL_CONFIG  *g_HcUserConfig_p)
{
	int32 fhandle = 0;
	uint32 writeCount;
	int32 result = 0;
	
	result = HcFile_Open(&fhandle, (int8*)HCUSER_CONFIG_F ,PO_WRONLY, 0);

	if( !result )
	{
		if( fhandle > 0 )
		{
			HcFile_Close(fhandle, 0);
		}
		return result;
	}
	HcFile_Write(fhandle, g_HcUserConfig_p, sizeof(HCCALL_CONFIG), &writeCount);
	
	if(writeCount == sizeof(HCCALL_CONFIG))
	{
		result  = 1;
	}
	else
	{
		result  = 0;
	}
	
	HcFile_Close(fhandle, 0);    
	return result;
}


/********************************************************************
Function:		HcCall_CheckUsbIsInMassStorageMode
Description: 	check whether the sd card is in mass storage mode
Input:		bPopupTip: wheather show the tip info		
Output:
Return:		TURE:yes, FALSE:no
Notice:
*********************************************************************/
BOOL HcCall_CheckUsbIsInMassStorageMode()
{
#ifdef __USB_IN_NORMAL_MODE__
	if (mmi_usb_is_in_mass_storage_mode())
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
#else
	return FALSE;
#endif
}


/********************************************************************
Function:		HcCall_CheckSDCard
Description: 	check whether the sd card is exist
Input:		bPopupTip: whether show the tip info		
Output:
Return:		TURE:exist, FALSE:not exist
Notice:
*********************************************************************/
BOOL HcCall_CheckSDCard()
{
#ifdef __USB_IN_NORMAL_MODE__
	if ((FS_NO_ERROR != FS_GetDevStatus(MMI_CARD_DRV,FS_MOUNT_STATE_ENUM)))
	{
		return FALSE;
	}
	else
	{
		return TRUE;
	}
#else
	return TRUE;
#endif
}


/********************************************************************
Function:		HcCall_CheckSDCardNoMemory
Description: 	check whether our sd card has enough momery for downloading
Input:		void	
Output:
Return:		TURE:No memory; 
			FALSE:enough momory
Notice:		500K
*********************************************************************/
BOOL HcCall_CheckSDCardNoMemory()
{
	U16 path[20];
	S8 buf[20];
	S32 fs_ret;
	U64 disk_free_space;
	U64 disk_total_space;
	FS_DiskInfo disk_info;

	sprintf(buf, "%c:\\", HC_get_driver_char(HC_DRIVER_CARD));
	mmi_asc_to_ucs2((S8*)path, (S8*)buf);

	fs_ret = FS_GetDiskInfo(path, &disk_info, FS_DI_BASIC_INFO | FS_DI_FREE_SPACE);
	disk_free_space = 0;
	disk_total_space = 0;
	
	if (fs_ret >= 0)
	{
		disk_free_space = (U64)disk_info.FreeClusters * disk_info.SectorsPerCluster * disk_info.BytesPerSector;
		disk_total_space = (U64)disk_info.TotalClusters * disk_info.SectorsPerCluster * disk_info.BytesPerSector;
		if(disk_free_space<512000)
		{
			return TRUE;
		}
	}
	return FALSE;
}


BOOL hccall_check_simcard(void)
{
	if (mr_getNetworkID() == MR_NET_ID_NONE)
	{
		return FALSE;
	}
	else
	{
		return TRUE;
	}
}


/********************************************************************
Function:		Hccall_Update_Database_Cancle
Description: 	cancel the database updating
Input:		void
Output:		void
Return:		void
Notice:
*********************************************************************/
void Hccall_Update_Database_Cancle(void)
{
	hccall_stop_host_timer();
	hccall_net_close();
	GoBackHistory();
}


int g_dldpercent = 0;
U8 g_str_buffer[512] = {0};
extern UI_string_type MMI_message_string;
/********************************************************************
Function:		hccall_ui_update_dldprocess
Description: 	updating the downloading process window
Input:		percent: the downloading percent
Output:		void
Return:		void
Notice:
*********************************************************************/
void hccall_ui_update_dldprocess(int percent)
{
	g_dldpercent = percent;

	if (HcCall_CheckUsbIsInMassStorageMode())
	{
		hccall_net_close();
		
		if ((GetActiveScreenId() == SCR_ID_HCCALL_UPDATE_DOWNLOADING) ||
			(GetActiveScreenId() == SCR_ID_HCCALL_UPDATE_CONNECTING))
		{
			GoBackHistory();
		}
		else
		{
			DeleteScreenIfPresent(SCR_ID_HCCALL_UPDATE_DOWNLOADING);
			DeleteScreenIfPresent(SCR_ID_HCCALL_UPDATE_CONNECTING);
		}	

		return;
	}
	
	if (GetActiveScreenId() == SCR_ID_HCCALL_UPDATE_DOWNLOADING)
	{
		memset(g_str_buffer, 0, sizeof(g_str_buffer));
		kal_wsprintf((kal_wchar*)g_str_buffer, "%w%d%w", (kal_wchar*)GetString(STR_ID_HCCALL_DOWNLOADING), percent, L"%");

		MMI_message_string = (UI_string_type)g_str_buffer;
		cat66_update_progress_string();

		if (g_dldpercent >= 100)
		{
			GoBackHistory();
		}
	}
	else
	{
		if (g_dldpercent >= 100)
		{
			DeleteScreenIfPresent(SCR_ID_HCCALL_UPDATE_DOWNLOADING);
		}
	}
}


/********************************************************************
Function:		hccall_ui_handle_endkey
Description: 	handle the end key event
Input:		void
Output:		void
Return:		void
Notice:
*********************************************************************/
void hccall_ui_handle_endkey(void)
{
	FILE_TRACE("HCCALLUI :: hccall_ui_handle_endkey");
	hccall_stop_host_timer();
	hccall_net_close();
	DisplayIdleScreen();
}


/********************************************************************
Function:		hccall_ui_exit_downloading
Description: 	
Input:		void
Output:		void
Return:		void
Notice:
*********************************************************************/
static void hccall_ui_exit_downloading(void)
{
	//dsmTurnOffBackLight();
	TurnOffBacklight();
}


/********************************************************************
Function:		Hccall_ui_enter_downloadingwnd
Description: 	the downding process window's entrence
Input:		void
Output:		void
Return:		void
Notice:
*********************************************************************/
void Hccall_ui_enter_downloadingwnd(void)
{	
	EntryNewScreen(SCR_ID_HCCALL_UPDATE_DOWNLOADING, hccall_ui_exit_downloading, Hccall_ui_enter_downloadingwnd, NULL);

	//dsmTurnOnBackLight();
	TurnOnBacklight(0);

	memset(g_str_buffer, 0, sizeof(g_str_buffer));
	kal_wsprintf((kal_wchar*)g_str_buffer, "%w%d%w", (kal_wchar*)GetString(STR_ID_HCCALL_DOWNLOADING), g_dldpercent, L"%");
		
	ShowCategory165Screen(0, 0, 
					STR_GLOBAL_BACK, IMG_GLOBAL_BACK, 
					(UI_string_type)g_str_buffer, 
					0,
					NULL);

	SetRightSoftkeyFunction(Hccall_Update_Database_Cancle, KEY_EVENT_UP);
	SetKeyHandler(hccall_ui_handle_endkey, KEY_END, KEY_EVENT_DOWN);
}


/********************************************************************
Function:		hccall_ui_enter_connecting
Description: 
Input:		
Output:
Return:
Notice:
*********************************************************************/
void hccall_ui_enter_connecting(void)
{
	EntryNewScreen(SCR_ID_HCCALL_UPDATE_CONNECTING, NULL, hccall_ui_enter_connecting, NULL);
	ShowCategory165Screen(0, 0, 
					STR_GLOBAL_BACK, IMG_GLOBAL_BACK, 
					(UI_string_type)GetString(STR_ID_HCCALL_CHECKUPDATE), 
					0,
					NULL);

	SetRightSoftkeyFunction(Hccall_Update_Database_Cancle ,KEY_EVENT_UP);
	SetKeyHandler(hccall_ui_handle_endkey, KEY_END, KEY_EVENT_DOWN);
}


void hccall_ui_enter_findnewwnd(void);
/********************************************************************
Function:		hccall_ui_handle_download_evt
Description: 
Input:		
Output:
Return:
Notice:
*********************************************************************/
void hccall_ui_handle_download_evt(int event)
{
	if (event == HC_DLD_FINDNEW)
	{
		if (HcCall_CheckUsbIsInMassStorageMode())
		{
			hccall_net_close();
		}
		else
		{
			Hccall_ui_enter_downloadingwnd();
		}
	}
	else if (event == HC_DLD_ISNEW)
	{
		DisplayPopup((PU8) GetString(STR_ID_HCCALL_ISNEW), IMG_GLOBAL_WARNING,  1,  UI_POPUP_NOTIFYDURATION_TIME,  0);		
	}
	else if (event == HC_DLD_CONERROR)
	{
		DisplayPopup((PU8) GetString(STR_ID_HCCALL_TIMEOUT), IMG_GLOBAL_WARNING,  1,  UI_POPUP_NOTIFYDURATION_TIME,  0);		
	}
	else if (event == HC_DLD_NETERROR)
	{
		DisplayPopup((PU8) GetString(STR_ID_HCCALL_NETERROR), IMG_GLOBAL_WARNING,  1,  UI_POPUP_NOTIFYDURATION_TIME,  0);
		DeleteScreenIfPresent(SCR_ID_HCCALL_UPDATE_DOWNLOADING);
	}
	else if (event == HC_DLD_SERVERERROR)
	{
		DisplayPopup((PU8) GetString(STR_ID_HCCALL_SERVERERROR), IMG_GLOBAL_WARNING,  1,  UI_POPUP_NOTIFYDURATION_TIME,  0);	
	}

	DeleteScreenIfPresent(SCR_ID_HCCALL_UPDATE_CONNECTING);
}


//#ifdef __SKYENGINE_V2__
extern void mr_sim_initialize(void);
//#else
//extern void dsmInitSimInfo(void);
//#endif

/********************************************************************
Function:		Hccall_Update_Database
Description: 
Input:		
Output:
Return:
Notice:
*********************************************************************/
void hccall_ui_start_download(void)
{
	GoBackHistory();

	FILE_TRACE("HCCALLUI :: hccall_ui_start_download start");

//#ifdef __SKYENGINE_V2__
	mr_sim_initialize();
//#else
//	dsmInitSimInfo();
//#endif

	if (!hccall_check_simcard())
	{
		FILE_TRACE("HCCALLUI :: have no sim card!");
		DisplayPopup((PU8) GetString(STR_ID_HCCALL_INSERTSIM), IMG_GLOBAL_WARNING,  1,  UI_POPUP_NOTIFYDURATION_TIME,  0);		
		return;
	}
	
	if (!HcCall_CheckSDCard())
	{
		FILE_TRACE("HCCALLUI :: have no sd card");
		DisplayPopup((PU8) GetString(STR_ID_HCCALL_INSERTSD),IMG_GLOBAL_WARNING, 0, UI_POPUP_NOTIFYDURATION_TIME, WARNING_TONE); 
		return;
	}
	
	if (HcCall_CheckUsbIsInMassStorageMode())
	{
		FILE_TRACE("HCCALLUI :: in usb massstorage mode");
#ifndef WIN32
		mmi_usb_app_unavailable_popup(0); 
#endif
		return;
	}
	
	if(HcCall_CheckSDCardNoMemory())
	{
		FILE_TRACE("HCCALLUI :: sd card have no memory");
		DisplayPopup((PU8) GetString(STR_ID_HCCALL_NOMEMORY), IMG_GLOBAL_WARNING,  1,  UI_POPUP_NOTIFYDURATION_TIME,  0);		
		return;
	}

	FILE_TRACE("HCCALLUI :: start dial");
	g_dldpercent = 0;
	hccall_ui_enter_connecting();
	hccall_net_dial(16793108);
}


/********************************************************************
Function:		hccall_ui_enter_gprs_alert
Description: 	update
Input:		void
Output:		void
Return:		void
Notice:
*********************************************************************/
void hccall_ui_enter_gprs_alert(void)
{
	EntryNewScreen(SCR_ID_HCCALL_UPDATE_GPRSALERT, NULL, hccall_ui_enter_gprs_alert, NULL);
	ShowCategory165Screen(STR_GLOBAL_OK, IMG_GLOBAL_OK, 
						STR_GLOBAL_BACK, IMG_GLOBAL_BACK, 
						(UI_string_type)GetString(STR_ID_HCCALL_TIP), 
						0,
						NULL);

	DeleteScreenIfPresent(SCR_ID_HCCALL_UPDATE_NEWVERSION);

	SetLeftSoftkeyFunction(hccall_ui_start_download,KEY_EVENT_UP);
	SetRightSoftkeyFunction(GoBackHistory ,KEY_EVENT_UP);	

	SetCenterSoftkeyFunction(hccall_ui_start_download, KEY_EVENT_UP);
	ChangeCenterSoftkey(NULL, IMG_GLOBAL_COMMON_CSK);
}



/********************************************************************
Function:		Hccall_Update_Database
Description: 
Input:		
Output:
Return:
Notice:
*********************************************************************/
void hccall_ui_enter_findnewwnd(void)
{
	EntryNewScreen(SCR_ID_HCCALL_UPDATE_NEWVERSION, NULL, hccall_ui_enter_findnewwnd, NULL);

#ifndef __HCCALL_DATABASE_FIRM__
	if (FALSE == HcFile_IsExist((int8*)INDEX_DATA))
	{
		ShowCategory165Screen(STR_GLOBAL_OK, IMG_GLOBAL_OK, 
					STR_GLOBAL_BACK, IMG_GLOBAL_BACK, 
					(UI_string_type)GetString(STR_ID_HCCALL_NODATABASE), 
					0,
					NULL);
	}
	else
#endif
	{
		ShowCategory165Screen(STR_GLOBAL_OK, IMG_GLOBAL_OK, 
					STR_GLOBAL_BACK, IMG_GLOBAL_BACK, 
					(UI_string_type)GetString(STR_ID_HCCALL_NEWVERSION), 
					0,
					NULL);
	}

	SetLeftSoftkeyFunction(hccall_ui_enter_gprs_alert, KEY_EVENT_UP);
	SetRightSoftkeyFunction(GoBackHistory ,KEY_EVENT_UP);

	SetCenterSoftkeyFunction(hccall_ui_enter_gprs_alert, KEY_EVENT_UP);
	ChangeCenterSoftkey(NULL, IMG_GLOBAL_COMMON_CSK);
	
 	return;
}


/********************************************************************
Function:		hccall_ui_enter_mainmenu
Description: 	main menu window
Input:		void
Output:		void
Return:		void
Notice:		void
*********************************************************************/
void hccall_ui_enter_mainmenu(void)
{
	U16 nNumofItem = 0; 
	U8* guiBuffer = NULL;  
	U16 ImageList[MAX_SUB_MENUS];
	U16 nStrItemList[MAX_SUB_MENUS];

	EntryNewScreen(SCR_ID_HCCALL, NULL, hccall_ui_enter_mainmenu, NULL);
	
	guiBuffer = GetCurrGuiBuffer(SCR_ID_HCCALL);	
	nNumofItem = GetNumOfChild(MENU_ID_HCCALL);
	
	GetSequenceStringIds(MENU_ID_HCCALL,nStrItemList);
	GetSequenceImageIds(MENU_ID_HCCALL, ImageList);
	SetParentHandler(MENU_ID_HCCALL);
	RegisterHighlightHandler(ExecuteCurrHiliteHandler);
	
	ShowCategory15Screen(STR_ID_HCCALL, IMG_ID_HCCALL_MAIN, STR_GLOBAL_OK, IMG_GLOBAL_OK,
		 STR_GLOBAL_BACK, IMG_GLOBAL_BACK,  nNumofItem, nStrItemList, ImageList,  LIST_MENU, 0, guiBuffer);
	
	SetRightSoftkeyFunction(GoBackHistory,KEY_EVENT_UP);
}


/********************************************************************
Function:		Hccall_Update_Database
Description: 
Input:		
Output:
Return:
Notice:
*********************************************************************/
void hccall_ui_mianmunu_onleftkey(void)
{
	HcFile_CreateHccallDir();
	
	hccall_ui_enter_mainmenu();

	if (g_hccall_netstate != HCCALL_NET_STATE_IDLE)
	{
		hccall_net_close();
	}

#ifndef __HCCALL_DATABASE_FIRM__
	if (FALSE == HcFile_IsExist((int8*)INDEX_DATA))
	{
		hccall_ui_enter_findnewwnd();
	}
#endif
}


/********************************************************************
Function:		HighlightHcCallMainMenu
Description: 	
Input:		void
Output:		void
Return:		void
Notice:
*********************************************************************/
void HighlightHcCallMainMenu(void)
{
	SetLeftSoftkeyFunction(hccall_ui_mianmunu_onleftkey,KEY_EVENT_UP);
	SetRightSoftkeyFunction(GoBackHistory,KEY_EVENT_UP);
	
	SetCenterSoftkeyFunction(hccall_ui_mianmunu_onleftkey, KEY_EVENT_UP);
       ChangeCenterSoftkey(NULL, IMG_GLOBAL_COMMON_CSK);

}


  
 
/********************************************************************
Function:		HighlightUpdateDatabase
Description: 	update
Input:		void
Output:		void
Return:		void
Notice:
*********************************************************************/
void HighlightUpdateDatabase(void)
{
	SetLeftSoftkeyFunction(hccall_ui_enter_gprs_alert,KEY_EVENT_UP);
	SetRightSoftkeyFunction(GoBackHistory,KEY_EVENT_UP);

	SetCenterSoftkeyFunction(hccall_ui_enter_gprs_alert, KEY_EVENT_UP);
       ChangeCenterSoftkey(NULL, IMG_GLOBAL_COMMON_CSK);
}


void hccall_ui_enter_search_input(void);
/********************************************************************
Function:		hccall_ui_enter_search_result
Description: 	search a number's eara name
Input:		void
Output:		void
Return:		void
Notice:
*********************************************************************/
void hccall_ui_enter_search_result(void)
{
	U8*  guiBuffer;       /* Buffer holding history data */	
	S8*  buffer;
	S32  bufferSize;

	static S8 newbuffer[200];
	S8* gsdbuffer;
	memset(newbuffer, 0, sizeof(newbuffer));	
	
	EntryNewScreen(SCR_ID_HCCALL_SHOWRESULT_LOCSEARCH, NULL, hccall_ui_enter_search_result, NULL);
	//DeleteScreenIfPresent(SCR_ID_HCCALL_LOC_SEARCH);
	
	HistoryReplace(SCR_ID_HCCALL_LOC_SEARCH,SCR_ID_HCCALL_LOC_SEARCH, hccall_ui_enter_search_input);  
    
	guiBuffer = GetCurrGuiBuffer(SCR_ID_HCCALL_SHOWRESULT_LOCSEARCH);	

	if(mmi_ucs2strlen((const S8 *)g_HCStrGsdLocation) > 0)
	{
		buffer=(S8* )g_HCStrGsdLocation;
            
		gsdbuffer=GetString(STR_ID_HCCALL_GUISHUDI);
			
		mmi_ucs2cpy(newbuffer,g_HcStr_Number);
		mmi_ucs2cat(newbuffer, gsdbuffer);
		mmi_ucs2cat(newbuffer, buffer);						
	}
	else
	{
		buffer=(S8* )GetString(STR_ID_HCCALL_LOC_SEARCHERROR);//change
			            
		if(mmi_ucs2strlen((const S8 *)g_HcStr_Number) > 0)
		{
			mmi_ucs2cpy(newbuffer,g_HcStr_Number);
			mmi_ucs2cat(newbuffer, buffer);
		}
		else
		{
			mmi_ucs2cpy(newbuffer,buffer);	
		}
	}
        
	bufferSize=mmi_ucs2strlen((const S8 *)newbuffer);	
				
	ShowCategory74Screen(STR_ID_HCCALL_LOC_SEARCH, 
						0/*MAIN_MENU_TITLE_NETPHB_ICON*/, 
						0,	
						0,
						STR_GLOBAL_BACK,	
						IMG_GLOBAL_BACK,
						(PU8)newbuffer, 
						bufferSize,
						guiBuffer);
			
	memset(g_HCNumber,0,HCNUMBER_LEN*sizeof(char));
	
	SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
}


/********************************************************************
Function:		hccall_ui_start_search
Description: 	search a number's eara name
Input:		void
Output:		void
Return:		void
Notice:
*********************************************************************/
void hccall_ui_start_search(void)
{
	char str_num[HCNUMBER_LEN];
	char str_phNum[7];
	int pos = 0;
	
	memset(str_num, 0, sizeof(str_num));
	memset(str_phNum, 0, sizeof(str_phNum));
	memset(g_HCStrGsdLocation, 0, sizeof(g_HCStrGsdLocation));
	memset(g_HcStr_Number, 0, sizeof(g_HcStr_Number));
	
	if(mmi_ucs2strlen((const S8 *)g_HCNumber) > 0 )
	{
		mmi_ucs2_to_asc((S8 *)str_num, (S8 *)g_HCNumber);

		memset(g_HcStr_Number, 0, sizeof(g_HcStr_Number));
		mmi_ucs2cpy(g_HcStr_Number, g_HCNumber);
              		
		memset(g_HCNumber, 0, sizeof(g_HCNumber));		
		memset(&(wgui_inline_items[1]), 0, sizeof(InlineItem));				

		if(strlen((const char*)str_num) > 0)
		{
			if ((strlen((const char*)str_num) >= 2)
				&& (str_num[0]=='8')&&(str_num[1]=='6'))
			{                                     
				pos=2;                           
			}
			else if ((strlen((const char*)str_num) >= 4)
					&& (str_num[0]=='0') && (str_num[1]=='0') && (str_num[2]=='8') && (str_num[3]=='6'))
			{
				pos=4;
			}
			else
			{                    
				pos=0;              
			}
                
			memcpy(str_phNum,str_num+pos,7);  

			GetLocation_ex( g_HCStrGsdLocation,sizeof(g_HCStrGsdLocation),str_phNum );
		}
        
		hccall_ui_enter_search_result();
	}
	else
	{
		DisplayPopup((PU8) GetString(STR_GLOBAL_EMPTY),
					IMG_GLOBAL_EMPTY,
					1,
					1000,
					WARNING_TONE);
	}
}


/********************************************************************
Function:		hccall_ui_exit_search_input
Description: 	exit the search input window
Input:		void
Output:		void
Return:		void
Notice:
*********************************************************************/
void hccall_ui_exit_search_input(void)
{
    history h;
    U16 inputBufferSize;

    CloseCategory57Screen();
    h.scrnID = SCR_ID_HCCALL_LOC_SEARCH;
    h.entryFuncPtr = hccall_ui_enter_search_input;
	
    GetCategoryHistory(h.guiBuffer);
    inputBufferSize = (U16) GetCategory57DataSize();
    GetCategory57Data((U8*) h.inputBuffer);
    
    AddNHistory(h, inputBufferSize);
}


/********************************************************************
Function:		HighlightHcCallHistoryMenu
Description: 	search
Input:		void
Output:		void
Return:		void
Notice:
*********************************************************************/
void hccall_ui_enter_search_input(void)
{
	U8* guiBuffer; 
	U8* inputBuffer;
	U16 inputBufferSize;//added for inline edit history

	memset(g_HCNumber,0,HCNUMBER_LEN*sizeof(char));
	memset(g_HCStrLocation, 0, HCSTRLOCATION_LEN*sizeof(char));
	
	EntryNewScreen(SCR_ID_HCCALL_LOC_SEARCH, hccall_ui_exit_search_input, NULL, NULL);
	
	InitializeCategory57Screen();

	guiBuffer = GetCurrGuiBuffer(SCR_ID_HCCALL_LOC_SEARCH);
	inputBuffer = GetCurrNInputBuffer(SCR_ID_HCCALL_LOC_SEARCH, &inputBufferSize); 

	SetInlineItemActivation(&wgui_inline_items[0],INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
	SetInlineItemCaption(&wgui_inline_items[0],(U8*) GetString(STR_ID_HCCALL_LOC_SEARCH_TITLE));
	SetInlineItemActivation(&wgui_inline_items[1],INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
	SetInlineItemTextEdit(&wgui_inline_items[1], (PU8)g_HCNumber,16,IMM_INPUT_TYPE_NUMERIC);
	
	if(inputBuffer!=NULL)//added for inline edit history 
	{
		SetCategory57Data(wgui_inline_items, 2, inputBuffer);//sets the data 
	}
	
	DisableCategory57ScreenDone();
	
	ShowCategory57Screen(STR_ID_HCCALL_LOC_SEARCH,0,
						STR_GLOBAL_OK,NULL,
						STR_GLOBAL_BACK, IMG_GLOBAL_BACK,
						2,NULL,wgui_inline_items,0,guiBuffer);

	SetCategory57RightSoftkeyFunctions(hccall_ui_start_search, GoBackHistory);
}


/********************************************************************
Function:		HighlightHcCallLocSearchMenu
Description: 	search phone number's area
Input:		void
Output:		void
Return:		void
Notice:
*********************************************************************/
void HighlightHcCallLocSearchMenu(void)
{
	memset(g_HCNumber, 0, sizeof(g_HCNumber));
	
	SetLeftSoftkeyFunction(hccall_ui_enter_search_input, KEY_EVENT_UP);
	SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
	
	SetCenterSoftkeyFunction(hccall_ui_enter_search_input, KEY_EVENT_UP);
       ChangeCenterSoftkey(NULL, IMG_GLOBAL_COMMON_CSK);
}



/********************************************************************
Function:		hccall_get_sectiondatabase_md5
Description: 	
Input:		void
Output:		void
Return:		
Notice:
*********************************************************************/
int32 hccall_get_sectiondatabase_md5(char *pbuffer, int32 bufsize)
{
	int32 ret = 0;
	int32 filehandle = 0;
	uint32 readcount = 0;
	uint16 filemode = 0; 
	
	if (pbuffer == NULL)
	{
		return 0;
	}
	memset(pbuffer, 0, bufsize);

	ret = HcFile_Open(&filehandle, (int8*)SETION_DATAFILE, 0, 0);
	if(ret ==  FALSE)
	{
		HcFile_Close(filehandle, 0);

		if(HcFile_Open(&filehandle, (int8*)mr_section, (uint32)sizeof(mr_section), 1))
		{
			filemode=1;
		}
		else
		{
			return FALSE;
		}
	}

	ret = HcFile_Seek(filehandle, 8, PSEEK_SET, filemode);
	if (ret == FALSE)
	{
		HcFile_Close(filehandle, filemode);
		return 0;
	}
	
	
	ret = HcFile_Read(filehandle, pbuffer, bufsize>32?32:bufsize, &readcount, filemode);
	if (ret == FALSE)
	{
		HcFile_Close(filehandle, filemode);
		return 0;
	}
	HcFile_Close(filehandle, filemode);
	
	return 1;
}


extern T_DSM_DUALSIM_SET dsmDualSim;

/********************************************************************
Function:		hccall_ui_start_save_func_setting
Description: 	save function settings
Input:		void
Output:		void
Return:		void
Notice:
*********************************************************************/
void hccall_ui_start_save_func_setting(void)
{
	g_hccall_confg.functionset = Hc_func_setting_item;
	
	hccall_save_userconfig(&g_hccall_confg);

	DisplayPopup((PU8) GetString(STR_GLOBAL_DONE),
				IMG_GLOBAL_ACTIVATED,
				1,
				1000,
				WARNING_TONE);	

	DeleteScreenIfPresent(SCR_ID_HCCALL_FUNC_SETTING);

	return;
}


/********************************************************************
Function:		hccall_ui_func_set_hilightindex
Description: 	
Input:		void
Output:		void
Return:		void
Notice:
*********************************************************************/
void hccall_ui_func_set_hilightindex(S32 nIndex)
{
	Hc_func_setting_item = (U16) nIndex;

	return;
}


/********************************************************************
Function:		hccall_ui_enter_func_setting
Description: 	open or close the hccall function
Input:		void
Output:		void
Return:		void
Notice:
*********************************************************************/
void hccall_ui_enter_func_setting(void)
{
	U16 nStrItemList[] = {STR_ID_HCCALL_FUNCTION_SETTING_ON,
						STR_ID_HCCALL_FUNCTION_SETTING_OFF};
	U8 nNumofItem = 2;
	U8 *guiBuffer;

	EntryNewScreen(SCR_ID_HCCALL_FUNC_SETTING, NULL, hccall_ui_enter_func_setting, NULL);
	guiBuffer = GetCurrGuiBuffer(SCR_ID_HCCALL_FUNC_SETTING);

	RegisterHighlightHandler(hccall_ui_func_set_hilightindex);
	ShowCategory11Screen(STR_ID_HCCALL_FUNCTION_SETTING,
						0,
						STR_GLOBAL_OK,
						0,
						STR_GLOBAL_BACK,
						0,
						nNumofItem,
						nStrItemList,
						g_hccall_confg.functionset,
						guiBuffer);

	SetLeftSoftkeyFunction(hccall_ui_start_save_func_setting, KEY_EVENT_UP);
	SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);

	SetCenterSoftkeyFunction(hccall_ui_start_save_func_setting, KEY_EVENT_UP);
	ChangeCenterSoftkey(NULL, IMG_GLOBAL_COMMON_CSK);

	return;
}


/********************************************************************
Function:		HighlightHcCallSettingMenu
Description: 	setting
Input:		void
Output:		void
Return:		void
Notice:
*********************************************************************/
void HighlightHcCallFuncSettingMenu(void)
{
	SetLeftSoftkeyFunction(hccall_ui_enter_func_setting,KEY_EVENT_UP);
	SetRightSoftkeyFunction(GoBackHistory,KEY_EVENT_UP);

	SetCenterSoftkeyFunction(hccall_ui_enter_func_setting, KEY_EVENT_UP);
       ChangeCenterSoftkey(NULL, IMG_GLOBAL_COMMON_CSK);
}



/********************************************************************
Function:		hccall_ui_init_globalvalue
Description: 	init the global values
Input:		void
Output:		void
Return:		void
Notice:		
*********************************************************************/
void hccall_init_globalvalue(void)
{
	int i = 0;
	int ret = 0;
    
	ret = hccall_load_userconfig(&g_hccall_confg);
	if(ret == 0)
	{		
		g_hccall_confg.functionset = 0;	
         
		hccall_save_userconfig(&g_hccall_confg);        
	}

	FILE_TRACE("hccall_init_globalvalue :: functionset=%d", 
				g_hccall_confg.functionset );
    
	Hc_func_setting_item = 0;

	memset(g_HCNumber, 0, sizeof(g_HCNumber));
	memset(g_HCStrLocation, 0, sizeof(g_HCStrLocation));

	hccall_set_firmdatabase((const unsigned char*)mr_ldzs, (uint32)sizeof(mr_ldzs));
	LocationData_Init_ex();
}




/********************************************************************
Function:		InitHcCallApp
Description: 	the entrence function of the hccall application
Input:		void
Output:		void
Return:		void
Notice:		this function is called when the phone is powered on
*********************************************************************/
void InitHcCallApp(void)
{
	FILE_TRACE("HCCALL :: InitHcCallApp");
	
	SetHiliteHandler( MENU_ID_HCCALL, HighlightHcCallMainMenu );

	SetHiliteHandler( MENU_ID_HCCALL_LOC_SEARCH, HighlightHcCallLocSearchMenu );
	
	SetHiliteHandler( MENU_ID_HCCALL_FUNCTION_SETTING, HighlightHcCallFuncSettingMenu);
	SetHiliteHandler( MENU_ID_HCCALL_UPDATEMANUAL, HighlightUpdateDatabase);

	HcFile_CreateHccallDir();

	gui_start_timer(1000, hccall_init_globalvalue);
}


#define ELSE else
#define IF_STRCMP(des,des_len) 	if(strncmp((const char*)g_HCNumber+pos, des, des_len) == 0) \
{ \
pos += des_len; \
} \


/********************************************************************
Function:		HcCall_hist_populate_call_list
Description: 	get the city's name from a phone number
Input:		city_number: cellphone or telephone number	
Output:		city_name: the city name
Return:		the length of the city's name
Notice:
*********************************************************************/
int HcCall_hist_populate_call_list(char *city_name, int city_name_size, char *city_number)
{
	int ret_len=0;

	FILE_TRACE("HCCALLUI :: HcCall_hist_populate_call_list-----start");

	if (city_name==NULL || city_number==NULL)
	{
		return 0;
	}

	FILE_TRACE("HCCALLUI :: HcCall_hist_populate_call_list-----functionset=%d, city_number=%s", g_hccall_confg.functionset, city_number);

	memset(city_name, 0, city_name_size);
	if(0 == g_hccall_confg.functionset)
	{
		int pos = 0;
		int len = 0;

       	memset(g_HCNumber, 0, sizeof(g_HCNumber));
		memset(g_HCStrLocation,0,sizeof(g_HCStrLocation));
   		
		if( strlen( ( const char * )city_number) > 10 && strlen( ( const char * )city_number ) < 62 )
		{
			strcpy(g_HCNumber, ( const char * )city_number);
			
			IF_STRCMP("17951",5)
			ELSE IF_STRCMP("12593",5)
			ELSE IF_STRCMP("17969",5)
			ELSE IF_STRCMP("17909",5)
				
			IF_STRCMP("+86",3)
			IF_STRCMP("0086",4)
				
			len = GetLocation_ex( g_HCStrLocation,sizeof(g_HCStrLocation),g_HCNumber + pos );
			FILE_TRACE("HCCALLUI :: HcCall_hist_populate_call_list----len=%d", len);
			if(len > 0 )
			{			
				mmi_ucs2cat((S8 *)city_name , (const S8 *) L"~~");
				mmi_ucs2ncat((S8 *)city_name , (const S8 *)g_HCStrLocation, city_name_size-4);
				ret_len = mmi_ucs2strlen((const S8 *)city_name);
			}
            		memset(g_HCStrLocation,0,sizeof(g_HCStrLocation));
			memset(g_HCNumber, 0, sizeof(g_HCNumber));			
		}
	}

	FILE_TRACE("HCCALLUI :: HcCall_hist_populate_call_list----ret_len=%d", ret_len);
	return ret_len;
}

e_unet_sim_type hccall_get_simId(void)
{
	int32 DsmSimId = dsmDualSim.simId[dsmDualSim.curActive];
	
	if (DSM_SLAVE_SIM == DsmSimId)
	{
		return UNET_SIM_SLAVE;
	}
#ifdef __MR_CFG_MULTI_SIM_CARD__
#if defined(__RAGENT_SIM3_SUPPORT__)
	else if (DSM_THIRD_SIM == DsmSimId)
	{
		return UNET_SIM_THIRD;
	}
#endif
#if defined(__RAGENT_SIM4_SUPPORT__)
	else if (DSM_FOURTH_SIM == DsmSimId)
	{
		return UNET_SIM_FOURTH;
	}
#endif
#endif
	else
	{
		return UNET_SIM_MASTER;
	}
}

void hccall_start_host_timer(U32 delay, FuncPtr funcPtr)
{
	StartTimer(HCCALL_UI_TIMER, delay, funcPtr);

	return;
}

void hccall_stop_host_timer(void)
{
	StopTimer(HCCALL_UI_TIMER);

	return;
}

#endif // __HC_CALL_NEW__


